﻿using AutoMapper;
using B.S.Sterilizationcenter.Domain.zyy;
using B.S.Sterilizationcenter.ErrorCode;
using B.S.Sterilizationcenter.Writer.API.Appliaction.Commends.Zyy;
using Kdbndp.TypeHandlers;
using MediatR;
using SqlSugar;

namespace B.S.Sterilizationcenter.Writer.API.Appliaction.CommandHandlers.Zyy
{
    public class UpdateReceivingApplicationHandler : IRequestHandler<UpdateReceivingApplicationcommand, ApiResult<int>>
    {
        private readonly ISqlSugarClient db;
        private readonly IMapper mapper;

        public UpdateReceivingApplicationHandler(ISqlSugarClient db,IMapper mapper)
        {
            this.db = db;
            this.mapper = mapper;
        }

        public async Task<ApiResult<int>> Handle(UpdateReceivingApplicationcommand request, CancellationToken cancellationToken)
        {
            try
            {
                ApiResult<int> result = new ApiResult<int>();
                var data = mapper.Map<ReceivingApplication>(request);
                var insert = db.Updateable(data).ExecuteCommand();
                if (insert > 0)
                {
                    result.Code = ApiEnums.修改成功;
                    result.Msg = "修改成功";
                }
                else
                {
                    result.Code = ApiEnums.修改失败;
                    result.Msg = "修改失败";
                }
                return result;
            }
            catch (Exception)
            {

                throw;
            }

        }
    }
}

